<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>vue</title>
</head>
<script src="vue.js"></script>
<script src="vue-router.js"></script>
<body>
    <div id="app">
        <router-link to="/content">内容</router-link>
        <router-view></router-view>
    </div>

    <script type="text/x-template" id="content">
        <div>
           id:{{id}}
            <br>
            <button @click="show()">查看参数</button>
        </div>
    </script>
<script>

    const content={
        template:'#content',
        data(){
          return{
              id:0
          }
        },
        mounted(){
          this.id=this.$route.params.id;
          if(!this.id){
              this.id=1;
          }
        },
        methods:{
            show(){
                console.log(this.$route.params.id);
            }
        }

    };

//     routes:[
//        {path:'/hdphp',component:hdphp},
//        {path:'/hdcms',component:hdcms},
//    ];
    //组件交给路由器
    let route = new VueRouter({
        routes:[
            {path:'/content/:id?',component:content},
        ]
    });


    var app=new Vue({
        el:'#app',
        router:route,

        data:{
            type:true,
            title:'后端君',
        }
    });

</script>

</body>
</html>